/* James McTaggart (jcm28) Informatics
Multimedia Communications Technology - 17th May 2007
In making this submission I declare that my work contains no examples
of misconduct, such as plagiarism, collusion, or fabrication of results.
*/

package server;

import java.io.BufferedReader;
import java.io.InputStream;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.Vector;

public class UserInputThread extends Thread {

	private DatagramSocket socket;
	private BufferedReader  in;
	private boolean bleep = false;
	private Vector<Connection> connections;
	
	public UserInputThread(BufferedReader in, DatagramSocket socket,Vector<Connection> connections) {
		this.in = in;
		this.socket = socket;
		this.connections = connections;
	}
	
	
	@Override
	public void run() {
		while(true){
			try {
				String inString = in.readLine();
				if(inString.equals("BLEEP")||inString.equals("B")){
					bleep = !bleep;
				}
				else if(inString.equals("EXIT"))System.exit(0);
				if(bleep){
					for(Connection c:connections){
						socket.send(ServerProtocol.get202(c.getIp(),c.getPort()));
					}
				}
				else{
					for(Connection c:connections){
						socket.send(ServerProtocol.get203(c.getIp(),c.getPort()));
					}
				}
			} catch (Exception e){}
		}
	}
	
}
